from flask import Blueprint
from flasgger import Swagger

# 创建API v1蓝图
api_v1 = Blueprint('api_v1', __name__)

# 导入认证文档
from app.api.v1.docs.auth_docs import AUTH_DOC, GET_TOKEN_DOC

# 配置Swagger
swagger_config = {
    "headers": [],
    "specs": [
        {
            "endpoint": 'apispec_1',
            "route": '/apispec_1.json',
            "rule_filter": lambda rule: True,
            "model_filter": lambda tag: True,
        }
    ],
    "static_url_path": "/flasgger_static",
    "swagger_ui": True,
    "specs_route": "/apidocs/",
    "securityDefinitions": AUTH_DOC["securityDefinitions"],
    "security": AUTH_DOC["security"]
}

# 导入各个模块的路由
# 注意：大部分模块直接在api_v1蓝图上注册路由，只有部分模块使用子蓝图

# 导入原有的混合接口（保持向后兼容）
from app.api.v1.user import auth, order, payment, banner
from app.api.v1.admin import admin_auth, banner_management, user_management, order_management, dashboard, venue_management, activity_management, order_fixed, payment_config_management
from app.api.v1.common import upload
from app.api.v1.common.token import get_token_bp

# 导入新的按权限分离的用户端API
from app.api.v1.user_api import user_api

# 导入新的admin端API
from app.api.v1.admin import admin_bp

# 导入公共接口
from app.api.v1.common.venue_categories import venue_categories_bp
from app.api.v1.common.token_refresh import token_refresh_bp
from app.api.v1.common.test_login import test_login_bp

# 注册新的用户端API蓝图
api_v1.register_blueprint(user_api, url_prefix='/user_api')

# 注册新的admin端API蓝图
api_v1.register_blueprint(admin_bp, url_prefix='/admin')

# 注册公共接口蓝图
api_v1.register_blueprint(venue_categories_bp, url_prefix='/common')
api_v1.register_blueprint(get_token_bp, url_prefix='/common')
api_v1.register_blueprint(token_refresh_bp, url_prefix='/common')
api_v1.register_blueprint(test_login_bp, url_prefix='/common')

# 注册使用子蓝图的模块（保持向后兼容）
try:
    api_v1.register_blueprint(banner.user_banner_bp, url_prefix='/user')
except AttributeError:
    pass

# 注册管理员端API
api_v1.register_blueprint(banner_management.banner_bp, url_prefix='/admin')
api_v1.register_blueprint(user_management.user_management_bp, url_prefix='/admin')
api_v1.register_blueprint(dashboard.dashboard_bp, url_prefix='/admin')
api_v1.register_blueprint(activity_management.activity_management_bp, url_prefix='/admin')
api_v1.register_blueprint(upload.upload_bp, url_prefix='/common')

# 其他模块(auth, venue, order, payment, admin_auth, venue_management, order_management)
# 直接在api_v1蓝图上注册路由，不需要额外注册
